<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-10-08 15:52
 *
 * Version: 2.0
 */

namespace App\Modules\System\Criterias;


use Flower\Core\Repository\Contracts\RepositoryInterface;
use Flower\Core\Repository\Criterias\BaseCriterias;

class getContributionOrderListCriteria extends BaseCriterias
{
	private $params;

	public function  __construct($storeId,$barberId,$startDate,$endDate,$isProfit=0)
	{
		$this->params = [
			'store_id' => $storeId,
			'barber_id' => $barberId,
			'start_date' =>$startDate,
			'end_date'  => $endDate,
			'is_profit' => $isProfit
		];
	}

	public function apply($model, RepositoryInterface $repository)
	{
		return $model->select(['id','created_at','profit','category','link_id'])

//			->with(['items'=>function($v){
//			$v->with(['service'=>function($query){
//				$query->select(['id','type'])->with(['category'=>function($v){
//					$v->select(['id','resource'])->with('picture:id,image');
//				}]);
//			}]);
//		}])
			->whereRaw('store_id ="' . $this->params['store_id'] . '" and user_id="'.$this->params['barber_id'].'" and DATE_FORMAT(created_at,\'%Y-%m-%d\') <= "' .$this->params['start_date']. '" and DATE_FORMAT(created_at,\'%Y-%m-%d\') >="' . $this->params['end_date'] . '"')
			->orderBy('created_at','desc');

	}
}